Java.perform(function(){
    try {
        var Gson = Java.use('com.google.gson.Gson');
        var gson = Gson.$new();
        var Proxy = Java.use("java.lang.reflect.Proxy");
        var ShopAPI = Java.use("com.ss.android.ugc.aweme.ecommerce.showcase.service.api.ShopApi");
        var InvocationHandler = Java.use("java.lang.reflect.InvocationHandler");
        var oWj=Java.use("X.0Wj")
        var obj = Java.use("java.lang.Object")
    } catch (e) {
        console.log("加载工具类失败"+e.stack)
    }



    function dumpInstance(instance) {
            try {
                try {
                    var Gson = Java.use('com.google.gson.Gson');
                    var gson = Gson.$new();
                    console.log("获取gson成功");
                } catch (error) {
                    console.log("获取gson失败");
                }
                //var jclazz = instance.getClass();
                var className = instance.getName();
                console.log(`\n====== 开始打印实例 ${className}@${instance.hashCode()} 的信息 ======`);
        
                // --- 打印字段 ---
                console.log("  [+] 字段 (Fields):");
                var fields = instance.getDeclaredFields();
                if (fields.length === 0) {
                    console.log("无字段");
                } else {
                    fields.forEach(function(field) {
                        try {
                            // 修正：对单个 field 设置 setAccessible
                            field.setAccessible(true);
                            
                            var fieldName = field.getName();
                            var fieldType = field.getType().getName();
                            
                            // 核心修正：从 instance 对象中获取字段值
                            var fieldValue = field.get(instance); 
                            
                            // 对值进行更友好的展示
                            var fieldValueStr =fieldValue;
                            if (fieldValue && typeof fieldValue.toString === 'function') {
                                 try {
                                   //fieldValueStr = fieldValue.toString();
                                   fieldValueStr = gson.LJIILL(fieldValueStr);
                                 } catch (e) {
                                     // toString 可能会失败，例如对于一些代理类
                                     fieldValueStr = `[无法调用 toString(): ${e.message}]`;
                                 }
                            }
                            
                            console.log(` =======${fieldName}  (${fieldType}): ${fieldValueStr}`);
                        } catch (e) {
                            console.log(`    获取字段 ${field.getName()} 的值失败: ${e.message}`);
                        }
                    });
                }
        
                // --- 打印方法 ---
                console.log("\n  [+] 方法 (Methods):");
                var methods = instance.getDeclaredMethods();
                if (methods.length === 0) {
                    console.log("    无方法");
                } else {
                    methods.forEach(function(method) {
                        var methodName = method.getName();
                        var returnType = method.getReturnType().getName();
                        var parameterTypes = method.getParameterTypes().map(function (p) { return p.getName(); }).join(", ");
                        console.log(`    ${methodName}(${parameterTypes}): ${returnType}`);
                    });
                }
                console.log(`====== 实例 ${className}@${instance.hashCode()} 信息打印完毕 ======\n`);
        
            } catch (e) {
                console.log(`dumpInstance 失败：${e}`);
            }
        }
    function hookC42811Gr1(){
        try {
            const Gr1=Java.use("X.Gr1");
            const Gr1Class = Gr1.class;
            console.log("Gr1Class:"+Gr1Class)
            //dumpInstance(Gr1Class);
            //  Gr1.invokeSuspend.overload("java.lang.Object").implementation(function(obj){
            //     console.log("invokeSuspend被调用");
            //     reslut = this.invokeSuspend(obj);
            //     console.log("结果："+reslut);
            //     return reslut;
            // })

            let apiImpl = null;

            Java.choose("com.ss.android.ugc.aweme.ecommerce.showcase.service.api.ShopApi",{
                onMatch:function(inst){
                    apiImpl = inst;
                    return "stop";
                },
                onComplete:function(){}
            });
            
            if(apiImpl == null){
                console.log("没有找到ShopAPi的代理实例");
                return;
            }
            const handler = Proxy.getInvocationHandler(apiImpl);
            const oldInvoke = handler.invoke;
            handler.invoke = function(proxy,method,args){
                const methodName = method.getName();
                console.log("[+] 方法："+ methodName+"args"+JSON.stringify(args));
                if(methodName === "getShopFirstScreen"){
                    argsLength = args.length;
                    for(i=0;i<argsLength;i++){
                        console.log(`参数${i} : ${args[i]}`);
                    }
                }
                const result = oldInvoke.call(handler,proxy,method,args);
                console.log("接口名："+ methodName + "[+]结果"+result)
            }

        } catch (e) {
            console.log("hook失败"+e.stack)
        }
    }
    function hookC54782Cs(){
        console.log("开始尝试hookC54782Cs")
        const TCs = Java.use("X.2Cs");
        TCs.LIZ.implementation=function(){
            console.log("C54782Cs被调用");
            let result = this.LIZ();
            console.log("结果:"+ result);
            return result;
        };
        
    }
    function hookInvocationHandler(){
        
    }
    function hookshopScreen(){
        let ShopApi = Java.use("com.ss.android.ugc.aweme.ecommerce.showcase.service.api.ShopApi");
        ShopApi.getShopFirstScreen.implementation = function () {
            console.log('getShopFirstScreen is called');
            let ret = this.getShopFirstScreen();
            console.log('getShopFirstScreen ret value is ' + ret);
            return ret;
        };
    }
    

    try {
        console.log("------------>开始hook<----------");
        //hookshopScreen();
        hookC54782Cs();
    } catch (e) {
        console.log("[!]hook出现错误："+e.stack)
    }
})